var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}

function action(f, c, b) {
    if (status == 0 && f == 0) {
        cm.dispose();
        return
    }(f == 1) ? status++ : status--;
    selectionLog[status] = b;
    var a = -1;
    if (status <= a++) {
        cm.dispose()
    } else {
        if (status === a++) {
            var g = cm.getNpc() - 9400256;
            var d = 4036000 + g;
            if (cm.getNumberFromQuestInfo(63099, "door") == 12) {
                cm.playerMessage(-1, "所有的锁全部打开，巨门缓缓开启。");
                cm.curNodeEventEnd(true);
                cm.setInGameDirectionMode(true, false, true);
                cm.fieldEffect_InsertCanvas(1, 255, 240, 240, 240, 3000, 0);
                cm.inGameDirectionEvent_AskAnswerTime(3000)
            } else {
                if (cm.getNumberFromQuestInfo(63099, "" + g) > 1) {
                    cm.dispose();
                    cm.playerMessage(5, "已经打开了这把锁。")
                } else {
                    if (cm.haveItem(d)) {
                        cm.dispose();
                        cm.afterlandChangeMapObject("Key" + g + "_Open", 1, 1, 3000, 0, 0, 0, 0);
                        cm.afterlandChangeMapObject("Key" + g + "_Close", 1, 0, 3000, 0, 0, 0, 0);
                        cm.playerMessage(-1, "锁发出哐-的一声，打开了。");
                        cm.addNumberForQuestInfo(63099, "door", 1);
                        cm.addNumberForQuestInfo(63094, "" + g, 1);
                        cm.gainItem(d, -1)
                    } else {
                        cm.dispose();
                        if (cm.isQuestActive(63032)) {
                            cm.addNumberForQuestInfo(63032, "click", 1, 0, 12)
                        }
                        cm.playerMessage(5, "没有可以开门的钥匙。")
                    }
                }
            }
        } else {
            if (status === a++) {
                var e = cm.getNumberFromQuestInfo(63099, "enterQ");
                if (e == 1) {
                    cm.warp(867113603, 1, true)
                } else {
                    if (e == 2) {
                        cm.warp(867113613, 2, true)
                    } else {
                        if (e == 3) {
                            cm.warp(867113623, 1, true)
                        } else {
                            cm.warp(867113633, 1, true)
                        }
                    }
                }
                cm.dispose();
                cm.setInGameDirectionMode(false, true, false);
                if (cm.getQuestStatus(63086) == 0) {
                    cm.forceStartQuest(63086, "");
                    cm.updateInfoQuest(63086, "first=1")
                }
            }
        }
    }
};